<template>
    <div>
        <div>
            <div class="row">
                <view class="bg-img bg-mask flex align-center"
                      style="background-image: url('/static/images/background.png'); height: 240px">
                    <view class="flex">

                        <img class="cu-avatar xl round" :src="association.logo">
                    </view>
                    <view class="padding-xl text-white">

                        <view class="padding-xs text-xxl text-bold">
                            {{association.association_name}}
                        </view>
                        <view class="padding-xs text-lg">
                            {{association.school_name }}
                        </view>
                    </view>
                </view>
            </div>
            <scroll-view scroll-x class="bg-white nav text-center">
                <view class="cu-item text-blue cur">首页</view>
            </scroll-view>


            <view class="cu-card dynamic no-card solid-top ">
                <view class="cu-item shadow">

                    <view class="flex-sub text-center">
                        <view class="solids-bottom padding-xs flex align-center">
                            <view class="flex-sub text-left padding-left margin">
                                <div class="row">
                                    <div class="col-md-12">
                                        <p>归属学院：{{ association.college_name }}</p>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-12">
                                        <p>组织会长：{{ association.name }}</p>
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="col-md-12">
                                        <p>组织描述：{{ association.description }}</p>
                                    </div>
                                </div>
                            </view>
                        </view>
                    </view>
                </view>
            </view>
            <view class="cu-list menu no-card ">
                <view v-if="association.is_admin == 1" class="cu-item arrow">
                    <navigator
                        @click="gotoPage"
                        class="content" hover-class="none"
                        data-url="/pages/association/check/check"
                        open-type="redirect">
                        <text class="cuIcon-all text-red"></text>
                        <text class="text-grey">组织审核</text>
                    </navigator>
                </view>

                <view v-if="association.is_admin == 1" class="cu-item arrow">
                    <navigator

                        @click="gotoPage"
                        class="content" hover-class="none"
                        data-url="/pages/association/notice/notice"
                        open-type="redirect">
                        <text class="cuIcon-message text-olive"></text>
                        <text class="text-grey">发布公告</text>
                    </navigator>
                </view>

                <view v-if="association.is_admin == 1" class="cu-item arrow">
                    <navigator
                        @click="gotoPage"
                        class="content" hover-class="none"
                        data-url="/pages/association/timetable/search"
                        open-type="redirect">
                        <text class="cuIcon-time text-blue"></text>
                        <text class="text-grey">无课表查询</text>
                    </navigator>
                </view>
                <view v-if="association.is_admin == 1" class="cu-item arrow">
                    <navigator
                        @click="gotoPage"
                        class="content" hover-class="none"
                        data-url="/pages/association/user/user"
                        open-type="redirect">
                        <text class="cuIcon-peoplelist text-yellow"></text>
                        <text class="text-grey">成员管理</text>
                    </navigator>
                </view>
                <view v-if="association.is_admin == 1" class="cu-item arrow">
                    <navigato
                        @click="gotoPage"
                        class="content" hover-class="none"
                        data-url="/pages/association/edit/edit"
                        open-type="redirect">
                        <text class="cuIcon-brand text-grey"></text>
                        <text class="text-grey">组织管理</text>
                    </navigato>
                </view>

                <view class="cu-item arrow"
                      v-if="association.member == 0">
                    <navigator
                        @click="join"
                        class="content" hover-class="none"
                        open-type="redirect">
                        <text class="cuIcon-add text-green"></text>
                        <text class="text-grey">加入组织</text>
                    </navigator>
                </view>
            </view>
        </div>
    </div>
</template>

<script>

const app = getApp();
export default {
    data() {
        return {
            association: {
                association_id: '',
                association_name: '',
                association_description: '',
                logo: '',
                college_name: '',
                school_name: '',
                name: '',
                is_admin: 0,
                member: 0,
            },
            id: 1,
        }
    },
    onLoad: function (e) {
        this.setData({
            id: e.id
        })
        this.getAssociation(e.id);
    },
    // onUnload: function () {
        
    // },
	onBackPress() {
		// uni.navigateBack();
		
		//清空页面栈，否则的话返回首页会出问题
		uni.reLaunch({
			url: '../../pages/association/list/list'
		});
	},
    onPullDownRefresh: function () {
        uni.stopPullDownRefresh();
    },
    methods: {

        gotoPage(e) {
            let url = e.currentTarget.dataset.url;
            console.log(url);
            uni.navigateTo({
                url: url + '?id=' + this.id
            });
        },
        getAssociation: function (id) {
            this.$myFunction.getData(app.globalData.ApiUrl + '/api/Android/getAssociationDetail', {
                SafeCode: uni.getStorageSync('SafeCode'),
                association_id: id
            }).then(res => {
                console.log(res);
                this.setData({
                    association: res.data
                })
            });
        },
        join: function () {
            let that = this;
            uni.showModal({
                title: '提示',
                content: '确定要加入该组织吗？',
                success: function (res) {
                    if (res.confirm) {
                        that.$myFunction.getData(app.globalData.ApiUrl + '/api/Android/joinAssociation', {
                            association_id: that.id,
                            SafeCode: uni.getStorageSync('SafeCode')
                        }).then(result => {
                            console.log(result);
                            if (result.code == 1) {
                                uni.showToast({
                                    title: '加入成功',
                                    icon: 'success',
                                    duration: 2000
                                });
                            } else {
                                uni.showToast({
                                    title: result.msg,
                                    icon: 'none',
                                    duration: 2000
                                });
                            }
                        });

                    } else if (res.cancel) {
                        uni.showToast({
                            title: '取消加入',
                            icon: 'none',
                            duration: 2000
                        });
                    }
                }
            });
        }
    }
}
</script>

<style scoped>
/** {*/
/*  border: black solid;*/
/*}*/
</style>